#include <bits/stdc++.h>
using namespace std;
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
using ll = long long;
void solve()
{
    ll n;
    cin >> n;
    vector<ll> a(n + 1);
    vector<ll> qz(n + 1), hz(n + 2,0);
    for(ll i=1;i<=n;i++)
    {
        cin >> a[i];
        if(a[i]>0) qz[i] =qz[i-1]+a[i];
        else
            qz[i] = qz[i - 1];

       // cout << qz[i] << " ";
    }
    //cout << endl;
    for(ll i=n;i>=1;i--)
    {
        if(a[i]<0)
        {
            hz[i] = hz[i + 1] - a[i];
        }
        else 
        {
            hz[i] = hz[i + 1];
        }
       // cout << hz[i] << " ";
    }
    //cout << endl;
    ll sum,ans=0;
    for (int i = 1; i <= n;i++)
    {
        sum = qz[i] + hz[i];
        ans = max(sum, ans);
    }

    cout << ans << endl;
}
int main()
{
    int t = 1;
    cin >> t;
    while(t--)
    {
        solve();
    }
   return 0;
}
